package com.dqyt.khjc.controller;

import com.alibaba.fastjson.JSON;
import com.dqyt.app.bean.Maintenance;
import com.dqyt.app.bean.Sample;
import com.dqyt.app.config.RepairType;
import com.dqyt.app.mongo.MaintenanceDao;
import com.dqyt.app.mongo.SampleDao;
import com.dqyt.common.check.CheckTool;
import com.dqyt.common.constant.AuthorityID;
import com.dqyt.common.utils.StringUtil;
import com.dqyt.common.utils.UserInfoUtil;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.bean.User;
import com.dqyt.khjc.service.MaintenanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 维修记录
 */
@RestController
public class MaintenanceController {


    @Autowired
    private MaintenanceService maintenanceService;



    /**
     * 添加维修记录
     * @param request
     * @param maintenance
     * @return
     */
    @RequestMapping(value = "/api/saveMaintenance", method = {RequestMethod.POST})
    public ResultMsg saveMaintenance(HttpServletRequest request,String maintenance){
        ResultMsg resultMsg = maintenanceService.saveMaintenance(request,maintenance);
        return resultMsg;
    }


    /**
     * 无实物 添加维修记录
     * @param request
     * @param maintenance
     * @return
     */
    @RequestMapping(value = "/api/saveMaintenanceWsw", method = {RequestMethod.POST})
    public ResultMsg saveMaintenanceWsw(HttpServletRequest request,String maintenance){
        ResultMsg resultMsg = maintenanceService.saveMaintenanceWsw(request,maintenance);
        return resultMsg;
    }



    /**
     * 添加维修记录
     * @param request
     * @param maintenance
     * @return
     */
    @RequestMapping(value = "/api/updateMaintenance", method = {RequestMethod.POST})
    public ResultMsg updateMaintenance(HttpServletRequest request,String maintenance){
        ResultMsg resultMsg = maintenanceService.updateMaintenance(request,maintenance);
        return resultMsg;
    }



    /**
     * 分页查询维修列表
     * @param request 请求
     * @param pageNum  页数
     * @param pageSize  每页条数
     * @param bsbh   标识编号
     * @param erweima  二维码
     * @param type  样品类型  1：呼吸器  2: 复合气瓶
     * @param wtfId  委托方id
     * @return
     */
    @RequestMapping(value = "/api/getMainteListPage", method = {RequestMethod.POST})
    public ResultMsg getMainteListPage(HttpServletRequest request,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                       @RequestParam(name = "erweima", required = false, defaultValue = "")  String erweima,
                                       @RequestParam(defaultValue = "0")Integer type,
                                       @RequestParam(defaultValue = "-1") Integer wtfId,
                                       @RequestParam(defaultValue = "0") Integer wtfIdChi,
                                       @RequestParam(name = "jyrqNian", required = false, defaultValue = "") String jyrqNian,
                                       @RequestParam(name = "jyrqYue", required = false, defaultValue = "") String jyrqYue,
                                       @RequestParam(name = "rwdbh", required = false, defaultValue = "") String rwdbh){

        ResultMsg resultMsg = maintenanceService.getMainteListPage(request,pageNum, pageSize, bsbh, erweima, type, wtfId,wtfIdChi,jyrqNian,jyrqYue,rwdbh);
        return resultMsg;
    }



    /**
     * 分页查询维修列表  自己的维修列表
     * @param request 请求
     * @param pageNum  页数
     * @param pageSize  每页条数
     * @param bsbh   标识编号
     * @param erweima  二维码
     * @param type  样品类型  1：呼吸器  2: 复合气瓶
     * @param wtfId  委托方id
     * @return
     */
    @RequestMapping(value = "/api/getMainteListPageMe", method = {RequestMethod.POST})
    public ResultMsg getMainteListPageMe(HttpServletRequest request,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                       @RequestParam(name = "erweima", required = false, defaultValue = "")  String erweima,
                                       @RequestParam(defaultValue = "0")Integer type,
                                       @RequestParam(defaultValue = "-1") Integer wtfId,
                                       @RequestParam(defaultValue = "0") Integer wtfIdChi,
                                       @RequestParam(name = "jyrqNian", required = false, defaultValue = "") String jyrqNian,
                                       @RequestParam(name = "jyrqYue", required = false, defaultValue = "") String jyrqYue,
                                       @RequestParam(name = "rwdbh", required = false, defaultValue = "") String rwdbh){

        ResultMsg resultMsg = maintenanceService.getMainteListPageMe(request,pageNum, pageSize, bsbh, erweima, type, wtfId,wtfIdChi,jyrqNian,jyrqYue,rwdbh);
        return resultMsg;
    }


    /**
     * 自己待审核的维修列表
     * @param request 请求
     * @param pageNum  页数
     * @param pageSize  每页条数
     * @param bsbh   标识编号
     * @param erweima  二维码
     * @param type  样品类型  1：呼吸器  2: 复合气瓶
     * @param wtfId  委托方id
     * @return
     */
    @RequestMapping(value = "/api/getMyMainteListPage", method = {RequestMethod.POST})
    public ResultMsg getMyMainteListPage(HttpServletRequest request,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(name = "bsbh", required = false, defaultValue = "")  String bsbh,
                                       @RequestParam(name = "erweima", required = false, defaultValue = "")  String erweima,
                                       @RequestParam(defaultValue = "0")Integer type,
                                       @RequestParam(defaultValue = "-1") Integer wtfId,
                                       @RequestParam(name = "jyrqNian", required = false, defaultValue = "") String jyrqNian,
                                       @RequestParam(name = "jyrqYue", required = false, defaultValue = "") String jyrqYue){

        ResultMsg resultMsg = maintenanceService.getMyMainteListPage(request,pageNum, pageSize, bsbh, erweima, type, wtfId,jyrqNian,jyrqYue);
        return resultMsg;
    }


    /**
     * 自己待审核的维修条数
     */
    @RequestMapping(value = "/api/getDshWxTot")
    public ResultMsg getDshWxTot(HttpServletRequest request){
        ResultMsg resultMsg = maintenanceService.getDshWxTot(request);
        return resultMsg;
    }



    /**
     * 查询维修记录
     * @param request
     * @param bsbh
     * @return
     */
    @RequestMapping(value = "/api/getMainteBybsbh", method = {RequestMethod.POST})
    public ResultMsg getMainteBybsbh(HttpServletRequest request,String bsbh){
        ResultMsg resultMsg = maintenanceService.getMainteBybsbh(request,bsbh);
        return resultMsg;
    }

    /**
     *  审核  维修
     * @param request
     * @return
     */
    @RequestMapping(value = "/api/examineMaintenance", method = {RequestMethod.POST})
    public ResultMsg examineMaintenance(HttpServletRequest request,String maintenance){
        ResultMsg resultMsg = maintenanceService.examineMaintenance(request,maintenance);
        return resultMsg;
    }

    /**
     *  删除维修
     * @param request
     * @return
     */
    @RequestMapping(value = "/api/deleteMainte", method = {RequestMethod.POST})
    public ResultMsg deleteMainte(HttpServletRequest request,String _id){
        ResultMsg resultMsg = maintenanceService.deleteMainte(request,_id);
        return resultMsg;
    }



}
